package com.zzgele.qmzb.api.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zzgele.qmzb.api.core.AbstractService;
import com.zzgele.qmzb.api.dao.VideoLikeMapper;
import com.zzgele.qmzb.api.dao.VideoListMapper;
import com.zzgele.qmzb.api.model.VideoLike;
import com.zzgele.qmzb.api.service.VideoLikeService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;


/**
 * Created by Martin on 2017/07/14.
 */
@Service(interfaceClass = VideoLikeService.class,proxy="jdk")
@Component
@Transactional
public class VideoLikeServiceImpl extends AbstractService<VideoLike> implements VideoLikeService {
    @Resource
    private VideoLikeMapper videoLikeMapper;
    @Resource
    private VideoListMapper videoListMapper;

    public  int like(Map<String, Object> map){
        try {
            int a=videoLikeMapper.isExist(map);
            if(a==0) {
                videoLikeMapper.like(map);
                videoListMapper.updateLike(map);
            }else{
                return  1;
            }
        }catch (Exception e){
            e.printStackTrace();
            //不能重复点赞
            return  1;
        }
        return 0;
    }


    public int dislike(Map<String, Object> map){
        int a=videoLikeMapper.isExist(map);
        if(a==1) {
            videoLikeMapper.dislike(map);
            videoListMapper.updateDislike(map);
        }
        return 0;

    }
}
